package com.changeover.security.server;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import com.changeover.security.client.IAuthenticationService;

@Service("authenticationService")
public class AuthenticationService implements IAuthenticationService {

    public String retrieveUsername() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

        if (authentication == null) {
            System.out.println("Not logged in");
            return null;
        } else {
            return (String) authentication.getPrincipal();
        }

    }
}
